package com.a214.yxz.yuejian013.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.a214.yxz.yuejian013.Activity.ClubVideoDetailActivity;
import com.a214.yxz.yuejian013.Base.BaseSFragment;
import com.a214.yxz.yuejian013.JavaBean.ClubvideoBean;
import com.a214.yxz.yuejian013.Adapter.ClubVideoAdapter;
import com.a214.yxz.yuejian013.Listener.ServiceListener;
import com.a214.yxz.yuejian013.Model.ResModel;
import com.a214.yxz.yuejian013.R;

import java.util.List;

/**
 * A simple {@link BaseSFragment} subclass.
 */
public class ClubVideoFragment extends BaseSFragment {
    private RecyclerView.LayoutManager layoutManager;
    private RecyclerView recyclerView;
    private ClubVideoAdapter adapter;
    private ServiceListener<List<ClubvideoBean>> listener;
    private ResModel model = new ResModel("gson",getSessionID());


    public ClubVideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club_video, container, false);
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView= (RecyclerView) view.findViewById(R.id.club_video_list);
        adapter=new ClubVideoAdapter(getContext());
        layoutManager=new LinearLayoutManager(getContext());

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(layoutManager);

        listener=new ServiceListener<List<ClubvideoBean>>() {
            @Override
            public void onResponse(final List<ClubvideoBean> l) {
                adapter.setList(l);
                adapter.setOnItemClickListener(new ClubVideoAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Intent intent=new Intent(getActivity(),ClubVideoDetailActivity.class);
                        intent.putExtra("url",l.get(position).getVideopath());
                        getActivity().startActivity(intent);
                    }

                    @Override
                    public void onItemLongClick(View view, int position) {

                    }
                });
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
            }
        };
        //model.getClubDetail("clubvideo",getActivity().getIntent().getStringExtra("club_id"),listener);
        model.getClubDetail("clubvideo","1",listener);
    }
}
